﻿//+-------------------------------------------------------------------------------------------------------------------------------------------------------
//
//Description: LocalizedParameterViewModel
//Author: Aravind Ramarathinam (aravr@microsoft.com)
//Copyright © Microsoft Corporation
//Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
//THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
//INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 
//See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
// 
//--------------------------------------------------------------------------------------------------------------------------------------------------------


using System.ComponentModel;

namespace VmroleAuthor.ViewModels
{   
    public class LocalizedParameterViewModel : ViewModelBase, IDataErrorInfo
    {
        private string parameterName;
        private string parameterValue;
        private readonly ViewDefResourcesContainerViewModel viewDefResourcesContainerViewModel;

        public LocalizedParameterViewModel(ViewDefResourcesContainerViewModel viewDefResourcesContainerViewModel)
        {
            this.viewDefResourcesContainerViewModel = viewDefResourcesContainerViewModel;
        }

        public static class PropertyNames
        {
            public const string ParameterName = "ParameterName";
            public const string ParameterValue = "ParameterValue";
        }

        public string ParameterName
        {
            get { return this.parameterName; }
            set
            {
                this.parameterName = value;
                this.OnPropertyChanged(PropertyNames.ParameterName);
            }
        }

        public string ParameterValue
        {
            get { return this.parameterValue; }
            set { this.parameterValue = value; this.OnPropertyChanged(PropertyNames.ParameterValue); }
        }


        public string this[string propertyName]
        {
            get
            {
                string error = null;
                switch (propertyName)
                {
                    case PropertyNames.ParameterName:
                        if (string.IsNullOrEmpty(this.ParameterName))
                        {
                            error = "Localized Parameter Name cannot be null or empty";
                        }
                        if (string.IsNullOrEmpty(error))
                        {
                            if (!this.viewDefResourcesContainerViewModel.CurrentLocalizedParameters.ContainsKey(this.ParameterName))
                            {
                                error = "Parameter not used by any of the viewdef parameters: " + this.ParameterName;
                            }
                        }
                        if (string.IsNullOrEmpty(error))
                        {
                            if (this.ParameterName.Contains(" "))
                            {
                                error = "Parameter cannot contain white space: " + this.ParameterName;
                            }
                        }
                        break;
                    case PropertyNames.ParameterValue:
                        if (string.IsNullOrEmpty(this.ParameterValue))
                        {
                            error = "Localized Parameter Value cannot be null or empty";
                        }
                        break;
                }
                return error;
            }
        }

        public string Error { get; set; }
    }
}
